<?php
namespace app\api\model\user;

use think\Model;
use think\Db;
class Giftmodel extends Model{
    /**
     *  查询用户收/送礼物列表
     */
    public function getGiftList($uid,$type){
        if($type == 'out'){ // 送出的礼物
            $where = ['gu.out_uid'=>$uid];
            $res = db('lj_gift_users')->alias('gu')
                ->field('u.nickname,u.photo,gu.gift_num,gu.create_time,g.gift_title,g.gift_pic')
                ->where($where)
                ->join('lj_users_baseinfo u','gu.in_uid = u.uid')
                ->join('lj_gift g','gu.gift_id=g.id')
                ->select();
        }else{
            $where = ['gu.in_uid'=>$uid];
            $res = db('lj_gift_users')->alias('gu')
                ->field('u.nickname,u.photo,gu.gift_num,gu.create_time,g.gift_title,g.gift_pic')
                ->where($where)
                ->join('lj_users_baseinfo u','gu.out_uid = u.uid')
                ->join('lj_gift g','gu.gift_id=g.id')
                ->select();
        }
        if($res){
            return $res;
        }else{
            return false;
        }
    }
}